//*******************************************************************************
// COPYRIGHT NOTES
// ---------------
// This is a sample for BCGControlBar Library Professional Edition
// Copyright (C) 1998-2016 BCGSoft Ltd.
// All rights reserved.
//
// This source code can be used, distributed or modified
// only under terms and conditions 
// of the accompanying license agreement.
//*******************************************************************************
//
// ChartDataTableView.cpp : implementation file
//

#include "stdafx.h"
#include "bcgpchartexample.h"
#include "ChartDataTableView.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CChartDataTableView

IMPLEMENT_DYNCREATE(CChartDataTableView, CBCGPChartExampleView)

CChartDataTableView::CChartDataTableView()
	: CBCGPChartExampleView(CChartDataTableView::IDD)
{
	//{{AFX_DATA_INIT(CChartDataTableView)
	m_bShowLegendKeys = TRUE;
	m_bInterlaceRows = TRUE;
	m_bHideSeries2Row = FALSE;
	m_bShowSeries3Row = TRUE;
	m_bCustomFormat = FALSE;
	m_bCustomColors = FALSE;
	m_bHorizontalLines = TRUE;
	m_bVerticalLines = TRUE;
	m_bOutlines = TRUE;
	m_bRoundValues = TRUE;
	//}}AFX_DATA_INIT
}

CChartDataTableView::~CChartDataTableView()
{
}

void CChartDataTableView::DoDataExchange(CDataExchange* pDX)
{
	CBCGPChartExampleView::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CChartDataTableView)
	DDX_Control(pDX, IDC_CHART, m_wndChart);
	DDX_Check(pDX, IDC_DATA_TABLE_LEGEND_KEYS, m_bShowLegendKeys);
	DDX_Check(pDX, IDC_INTERLACE_ROWS, m_bInterlaceRows);
	DDX_Check(pDX, IDC_HIDE_SERIES2_ROW, m_bHideSeries2Row);
	DDX_Check(pDX, IDC_SHOW_SERIES3_ROW, m_bShowSeries3Row);
	DDX_Check(pDX, IDC_CUSTOM_FORMAT, m_bCustomFormat);
	DDX_Check(pDX, IDC_CUSTOM_COLORS, m_bCustomColors);
	DDX_Check(pDX, IDC_DRAW_HORIZONTAL_LINES, m_bHorizontalLines);
	DDX_Check(pDX, IDC_DRAW_VERTICAL_LINES, m_bVerticalLines);
	DDX_Check(pDX, IDC_DRAW_OUTLINE, m_bOutlines);
	DDX_Check(pDX, IDC_ROUND_VALUES, m_bRoundValues);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CChartDataTableView, CBCGPChartExampleView)
	//{{AFX_MSG_MAP(CChartDataTableView)
	ON_BN_CLICKED(IDC_DATA_TABLE, OnUpdateChart)
	ON_BN_CLICKED(IDC_DATA_TABLE_LEGEND_KEYS, OnUpdateChart)
	ON_BN_CLICKED(IDC_INTERLACE_ROWS, OnUpdateChart)
	ON_BN_CLICKED(IDC_CUSTOM_FORMAT, OnUpdateChart)
	ON_BN_CLICKED(IDC_SHOW_SERIES3_ROW, OnUpdateChart)
	ON_BN_CLICKED(IDC_HIDE_SERIES2_ROW, OnUpdateChart)
	ON_BN_CLICKED(IDC_CUSTOM_COLORS, OnUpdateChart)
	ON_BN_CLICKED(IDC_DRAW_OUTLINE, OnUpdateChart)
	ON_BN_CLICKED(IDC_DRAW_VERTICAL_LINES, OnUpdateChart)
	ON_BN_CLICKED(IDC_DRAW_HORIZONTAL_LINES, OnUpdateChart)
	ON_BN_CLICKED(IDC_ROUND_VALUES, OnUpdateChart)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CChartDataTableView diagnostics

#ifdef _DEBUG
void CChartDataTableView::AssertValid() const
{
	CBCGPChartExampleView::AssertValid();
}

void CChartDataTableView::Dump(CDumpContext& dc) const
{
	CBCGPChartExampleView::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CChartDataTableView message handlers

void CChartDataTableView::OnInitialUpdate() 
{
	CBCGPChartExampleView::OnInitialUpdate();
	
	if (m_bIsReady)
	{
		return;
	}
	
	m_bIsReady = TRUE;
	
	CBCGPChartVisualObject* pChart = m_wndChart.GetChart();
	ASSERT_VALID(pChart);

	CBCGPInfoTipOptions infoTipOptions;
	infoTipOptions.m_StemLocation = CBCGPPopupWindow::BCGPPopupWindowStemLocation_BottomLeft;
	
	m_wndChart.EnableInfoTip(TRUE, &infoTipOptions);

	CBCGPChartSeries* pSeries1 = pChart->CreateSeries(_T("Series 1"), CBCGPColor(), BCGP_CT_DEFAULT, BCGPChartColumn);
	
	CBCGPChartSeries* pSeries2 = pChart->CreateSeries(_T("Series 2"));
	pSeries2->SetCurveType (BCGPChartFormatSeries::CCT_SPLINE_HERMITE);
	
	CBCGPChartSeries* pSeries3 = pChart->CreateSeries(_T("Series 3 (Hidden)"));
	pSeries3->m_bVisible = FALSE;

	pSeries1->AddDataPoint(0.752345);
	pSeries1->AddDataPoint(2.16354);
	pSeries1->AddDataPoint(5.673343);
	pSeries1->AddDataPoint(3.456434);
	pSeries1->AddDataPoint(3.58756);
	pSeries1->AddDataPoint(5.013636);
	pSeries1->AddDataPoint(8.345545);
	pSeries1->AddDataPoint(6.34233);
	pSeries1->AddDataPoint(4.897554);
	pSeries1->AddDataPoint(7.897466);
	pSeries1->AddDataPoint(9.343565);
	
	pSeries2->AddDataPoint(2.);
	pSeries2->AddDataPoint(4.);
	pSeries2->AddDataPoint(6.);
	pSeries2->AddDataPoint(7.);
	pSeries2->AddDataPoint(6.);
	pSeries2->AddDataPoint(3.);
	pSeries2->AddDataPoint(1.);
	pSeries2->AddDataPoint(0.);
	
	pSeries3->AddDataPoint(4.);
	pSeries3->AddDataPoint(1.);
	pSeries3->AddDataPoint(3.);
	pSeries3->AddDataPoint(6.);
	pSeries3->AddDataPoint(.5);
	pSeries3->AddDataPoint(8.);
	pSeries3->AddDataPoint(4.);
	pSeries3->AddDataPoint(2.);
	pSeries3->AddDataPoint(3.8);
	pSeries3->AddDataPoint(4.2);

	pChart->SetSeriesShadow();
	pChart->ShowDataMarkers();

	OnUpdateChart();
}

void CChartDataTableView::OnUpdateChart() 
{
	UpdateData();
	
	CBCGPChartVisualObject* pChart = m_wndChart.GetChart();
	ASSERT_VALID(pChart);

	BCGPChartFormatDataTable formatDataTable;

	formatDataTable.m_bShowLegendKeys = m_bShowLegendKeys;
	formatDataTable.m_bInterlaceRows = m_bInterlaceRows;
	formatDataTable.m_bRoundValues = m_bRoundValues;

	if (m_bCustomFormat)
	{
		formatDataTable.m_labelFormat.m_textFormat.SetFontSize(18.0);
		formatDataTable.m_labelFormat.m_textFormat.SetFontStyle(CBCGPTextFormat::BCGP_FONT_STYLE_ITALIC);
		formatDataTable.SetContentPadding(CBCGPSize(5.0, 5.0));
	}

	if (m_bCustomColors)
	{
		formatDataTable.m_labelFormat.m_brTextColor.SetColor(CBCGPColor::DodgerBlue);
		formatDataTable.m_brFill.SetColors(CBCGPColor::Bisque, CBCGPColor::Cornsilk, CBCGPBrush::BCGP_GRADIENT_PIPE_VERTICAL);
		formatDataTable.m_brInterlaceFill.SetColors(CBCGPColor::Lavender, CBCGPColor::AliceBlue, CBCGPBrush::BCGP_GRADIENT_PIPE_VERTICAL);

		formatDataTable.m_horizontalGridLinesFormat.m_brLineColor.SetColor(CBCGPColor::DodgerBlue);
		formatDataTable.m_horizontalGridLinesFormat.m_strokeStyle.SetDashStyle(CBCGPStrokeStyle::BCGP_DASH_STYLE_DASH);

		formatDataTable.m_verticalGridLinesFormat.m_brLineColor.SetColor(CBCGPColor::LightSalmon);

		formatDataTable.m_outlineFormat.m_brLineColor.SetColor(CBCGPColor::DodgerBlue);
		formatDataTable.m_outlineFormat.m_strokeStyle.SetDashStyle(CBCGPStrokeStyle::BCGP_DASH_STYLE_DOT);
	}

	formatDataTable.m_bDrawOutline = m_bOutlines;
	formatDataTable.m_bDrawVerticalGridLines = m_bVerticalLines;
	formatDataTable.m_bDrawHorizontalGridLines = m_bHorizontalLines;

	pChart->GetSeries(1)->m_bIncludeSeriesToDataTable = !m_bHideSeries2Row;
	pChart->GetSeries(2)->m_bIncludeInvisibleSeriesToDataTable = m_bShowSeries3Row;

	pChart->ShowDataTable(TRUE, &formatDataTable);

	pChart->SetDirty(TRUE, TRUE);
}

void CChartDataTableView::OnChartAnimation()
{
	if (IsAnimationAvailable())
	{
		CBCGPChartVisualObject* pChart = GetChart();
		if (pChart != NULL)
		{
			CBCGPChartSeries::BCGPChartAnimationStyle style = theApp.m_animationStyle;
			if (style == CBCGPChartSeries::BCGPChartAnimationStyle_Default)
			{
				style = CBCGPChartSeries::BCGPChartAnimationStyle_Slide;
			}

			pChart->StartAnimation(theApp.m_dblChartAnimationTime, theApp.m_animationType, style);
		}
	}
}
